#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<ld>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
using vvi = vector<vi>;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define nL "\n"
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int n; cin >> n;
vvi adj(n);
rep(i, 0, n - 1){
int a, b; cin >> a >> b; a--,b--;
adj[a].pb(b);
adj[b].pb(a);
}
vi ans(n + 1);
rep(i, 0, n){
vi ds;
auto dfs = [&](int cur, int p, int d, auto &&dfs)->void{
ds.pb(d);
for(int i : adj[cur]){
if(i == p) continue;
dfs(i, cur, d + 1, dfs);
}
};
dfs(i, -1, 0, dfs);
sort(all(ds));
int a = 0;
rep(j, 0, sz(ds)){
a += 2 * ds[j];
ans[j + 1] = max(ans[j + 1], (n - 1) * (j + 1) - a);
}
}
rep(i, 0, n + 1) cout << ans[i] << " ";
cout << nL;
return 0;
}
516. Longest Palindromic Subsequence | 468. Validate IP Address |
450. Delete Node in a BST | 445. Add Two Numbers II |
442. Find All Duplicates in an Array | 437. Path Sum III |
436. Find Right Interval | 435. Non-overlapping Intervals |
406. Queue Reconstruction by Height | 380. Insert Delete GetRandom O(1) |
332. Reconstruct Itinerary | 368. Largest Divisible Subset |
377. Combination Sum IV | 322. Coin Change |
307. Range Sum Query - Mutable | 287. Find the Duplicate Number |
279. Perfect Squares | 275. H-Index II |
274. H-Index | 260. Single Number III |
240. Search a 2D Matrix II | 238. Product of Array Except Self |
229. Majority Element II | 222. Count Complete Tree Nodes |
215. Kth Largest Element in an Array | 198. House Robber |
153. Find Minimum in Rotated Sorted Array | 150. Evaluate Reverse Polish Notation |
144. Binary Tree Preorder Traversal | 137. Single Number II |